<template>
  <div class="app-container customer-div">
    <el-form :model="customerForm" size="mini" label-width="140px" :rules="rules" ref="customerForm" style="width:1000px">
          <div style="margin-top: 20px">
            <svg-icon icon-class="marker" style="color: #606266"></svg-icon>
            <span class="font-small">客户信息</span>
          </div>
          <el-card shadow="never" style="margin-top:20px">
            <el-col :span="12">
              <el-form-item label="规模性质：" prop="newNature">
                <el-select v-model="customerForm.newNature" clearable :disabled="customerInfo.newNature!= '' && customerInfo.newNature!= null " @change="changenewNature">
                  <el-option v-for="(item,index) in newNatureList" :key="index" :value="item" :label="item"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="统一社会信用代码：" prop="businessCode">
                <el-input v-model.trim="customerForm.businessCode" @blur="seachRepeat" style="width:200px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="客户名称：" prop="customerName">
              <el-input v-model="customerForm.customerName" disabled style="width:250px"></el-input>
            </el-form-item>
            </el-col>
               <!-- 新增字段 -->
                 <el-col :span="12">
                  <el-form-item label="客户性质：" prop="customerQuality">
                    <el-select v-model="customerForm.customerQuality" clearable @change="changeQuality" :disabled="customerInfo.customerQuantity!= '' && customerInfo.customerQuantity!= null">
                      <el-option v-for="item in customerQualityList"  :key="item.cddId"  :value="item.cddId" :label="item.cddValue" :disabled="customerForm.newNature == 'Z2(撮合)' && item.cddId == '108'"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>

                <el-col :span="12">
                  <el-form-item label="客户规模：" prop="newScale" >
                    <el-select v-model="customerForm.newScale" clearable :disabled="customerInfo.newScale!= '' && customerInfo.newScale!= null">
                      <el-option v-for="(item,index) in newScaleList" :key="index" :value="item" :label="item"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>

<!--                <el-col :span="12">-->
<!--                  <el-form-item label="月用量：" prop="aboutBuyNum">-->
<!--                    <el-input type="number" v-model="customerForm.aboutBuyNum" style="width:200px" clearable></el-input>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
<!--                <el-col :span="12">-->
<!--                  <el-form-item label="预估吨毛利(元)：" prop="aboutPerProfit">-->
<!--                    <el-input type="number" v-model="customerForm.aboutPerProfit" style="width:200px" clearable></el-input>-->
<!--                  </el-form-item>-->
<!--                </el-col>-->
                <el-col :span="12">
                  <el-form-item label="创建人：">
                    {{customerInfo.createName}}
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="负责人：">
                    {{customerInfo.userName}}
                  </el-form-item>
                </el-col>
                <el-col :span="12" v-if="customerForm.customerContact[0]">
                  <el-form-item label="主联系人：" :prop="`customerContact[0].contactName`" :rules="rules.contactName">
                    <el-input v-model="customerForm.customerContact[0].contactName" style="width:150px"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12" v-if="customerForm.customerContact[0]">
                  <el-form-item label="主联系电话：" :prop="`customerContact[0].contactMobile`" :rules="rules.contactMobile">
                    <el-input v-model="customerForm.customerContact[0].contactMobile" style="width:150px" @blur="seachRepeat2"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="主联系人职位：" v-if="customerForm.customerContact[0]" :prop="`customerContact[0].contactDuty`" :rules="rules.contactDuty">
                     <el-select
                      v-model="customerForm.customerContact[0].contactDuty"
                      placeholder="请选择/输入"
                      clearable
                      filterable
                      allow-create
                      default-first-option>
                      <el-option v-for="(item,index) in contactDutyList" :key="index" :label="item" :value="item"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="是否有采购决定权：" v-if="customerForm.customerContact[0]" :prop="`customerContact[0].isBuyPermission`" :rules="rules.isBuyPermission">
                    <el-radio-group v-model="customerForm.customerContact[0].isBuyPermission">
                      <el-radio :label="1">是</el-radio>
                      <el-radio :label="0">否</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="开票是否明细：">
                    <el-radio-group v-model="customerForm.isInvoiceNeedDetail">
                      <el-radio :label="1">是</el-radio>
                      <el-radio :label="0">否</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="客户协助人：">
                    <el-select v-model="customerForm.subChargeIds" filterable placeholder="请选择" clearable multiple>
                      <el-option
                        v-for="item in userOptionList"
                        :key="item.userId"
                        :label="item.userName"
                        :value="item.userId">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="客户分类：" prop="customerNewType">
                    <el-select v-model="customerForm.customerNewType" placeholder="请选择" :disabled="(customerInfo.customerNewType!='' && customerInfo.customerNewType!=null) || customerForm.newNature == 'Z2(撮合)'" clearable>
                      <el-option
                        v-for="item in customerTypeList"
                        :key="item.cddValue"
                        :label="item.cddValue"
                        :value="item.cddValue">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <!-- 客户来源为客户转介绍 -->
                <!-- <el-col :span="12" v-if="customerForm.customerSource == 106">
                  <el-form-item label="推荐人：" prop="introducerId">
                    <el-select v-model="customerForm.introducerId">
                      <el-option :value="item.introducerId" :label="item.introducerName+'('+item.introducerMobile+')'" :key="item.introducerId" v-for="item in tjrList"></el-option>
                    </el-select>
                    <el-button type="text" style="margin-left:10px" @click="showTeiJian">新增</el-button>
                  </el-form-item>
                </el-col> -->
              </el-card>
           <!-- 新增字段 -->
          <div style="margin-top: 20px">
            <svg-icon icon-class="marker" style="color: #606266"></svg-icon>
            <span class="font-small">生产经营</span>
            <span>(以下内容均为客户下游的情况)</span>
          </div>
          <el-card shadow="never" style="margin-top:20px">
            <el-row>
                <el-col :span="8">
                  <el-form-item label="所属行业：">
                    <el-select
                      @change="changeNewIndustry"
                      v-model="customerForm.newIndustry"
                      placeholder="请选择/输入"
                      clearable
                      filterable
                      allow-create
                      default-first-option>
                      <el-option v-for="(item,index) in newIndustryList" :key="index" :label="item" :value="item"></el-option>
                      <el-option label="贸易" value="贸易" v-if="customerForm.customerQuality == 108"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="16">
                  <el-form-item label="主营产品：">
                    <el-input v-model="customerForm.mainProduct" clearable style="width: 300px;"></el-input>
                  </el-form-item>
                </el-col>
            </el-row>
           <el-table :data="customerForm.customerDownstream" border style="width: 100%;margin:10px 0 20px">
              <el-table-column
                width="250"
                align="center"
                label="下游客户">
                <template slot-scope="scope">
                  <el-form-item label-width="0px">
                    <el-input v-model="scope.row.downstreamName" clearable></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column
                label="需求产品"
                width="250"
                align="center">
                <template slot-scope="scope">
                  <el-form-item label-width="0px">
                    <el-input v-model="scope.row.product" clearable></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column  label="客户级别" width="150" align="center">
                <template slot-scope="scope">
                  <el-form-item label-width="0px">
                    <el-select v-model="scope.row.level" clearable>
                      <el-option v-for="(item,index) in levelList" :key="index" :label="item" :value="item"></el-option>
                    </el-select>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column  label="订单情况" width="200" align="center">
                <template slot-scope="scope">
                  <el-form-item label-width="0px">
                    <el-input v-model="scope.row.orderRemark" clearable></el-input>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column  label="操作" width="100" align="center" fixed="right">
                <template slot-scope="scope">
                  <el-button type="text" @click="delDownstream(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <el-button type="primary" size="small" @click="addDownstream">增加下游客户</el-button>

               <el-form-item label="回款情况：" style="margin-top:20px">
                <div class="flexTableStyle">
                   <el-select v-model="customerForm.returned" style="width: 150px;margin-right:10px;" clearable>
                    <el-option v-for="(item,index) in returnedList" :key="index" :label="item" :value="item"></el-option>
                  </el-select>
                  <el-form-item v-if="customerForm.returned=='账期'" prop="returnedDay" label="账期天数" label-width="80px">
                    <el-input-number
                      v-model="customerForm.returnedDay"
                      :min="1"
                      :controls="false"
                     :precision="0"
                      ></el-input-number>
                      <span>天</span>
                  </el-form-item>
                </div>
              </el-form-item>

              <el-form-item label="结算方式：" style="margin-top:20px">
                 <el-checkbox-group v-model="customerForm.settlement" style="display:flex;flex-direction:column;font-size:12px;">
                    <el-row>
                      <el-col :span="2">
                        <el-checkbox label="账期">账期</el-checkbox>
                      </el-col>
                      <el-col :span="22" v-if="customerForm.settlement.indexOf('账期')!=-1">
                        <div class="flexTableStyle">
                          <el-form-item label="利率(%):" label-width="80px" prop="interestRate">
                            <el-input-number
                              v-model="customerForm.interestRate"
                              :min="0"
                              :controls="false"
                              :precision="2"
                            ></el-input-number>
                          </el-form-item>
                          <el-form-item label="到期时间:" label-width="80px" prop="accountingPeriod">
                            <el-input-number
                              v-model="customerForm.accountingPeriod"
                              :min="1"
                              :controls="false"
                              :precision="0"
                              ></el-input-number>
                              <span>天</span>
                          </el-form-item>
                        </div>
                      </el-col>
                    </el-row>
                    <el-row style="margin-top:10px;margin-bottom:10px;">
                      <el-col :span="2">
                        <el-checkbox label="现金">现金</el-checkbox>
                      </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="2">
                        <el-checkbox label="承兑">承兑</el-checkbox>
                      </el-col>
                      <el-col :span="22" v-if="customerForm.settlement.indexOf('承兑')!=-1">
                        <el-form-item label="贴息点数:" label-width="80px" prop="subsidyInterest">
                          <el-input-number
                            v-model="customerForm.subsidyInterest"
                            :min="0"
                            :controls="false"
                            :precision="2"
                          ></el-input-number>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-checkbox-group>
              </el-form-item>
          </el-card>

          <div style="margin-top: 20px">
            <svg-icon icon-class="marker" style="color: #606266"></svg-icon>
            <span class="font-small">公司信息</span>
          </div>
          <el-card shadow="never" style="margin-top:20px">
             <el-row>
                  <el-col :span="8">
                      <el-form-item label="法人：" prop="legalPerson">
                        <el-input v-model="customerForm.legalPerson"></el-input>
                      </el-form-item>
                  </el-col>

                  <el-col :span="16">
                    <el-form-item label="成立日期：" prop="issueDate">
                      <el-date-picker
                        value-format="yyyy-MM-dd"
                        v-model="customerForm.issueDate"
                        type="date"
                        placeholder="选择日期">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
              </el-row>
                <el-form-item label="所在地区：" v-model="diQuIds" prop="diQuIds">
                  <el-cascader
                    filterable
                    @change="chooseAreaId"
                    v-model="diQuIds"
                    ref="diQuIds"
                    :props="{ value: 'areaId',label:'areaName',children:'areaChildList' }"
                    :options="options">
                  </el-cascader>
                </el-form-item>
                <el-form-item label="详细地址：" prop="regAddress">
                  <el-input v-model="customerForm.regAddress"></el-input>
                </el-form-item>
                <el-form-item label="经营范围：" prop="businessInfo">
                  <el-input v-model="customerForm.businessInfo" :autosize="{ minRows: 2, maxRows: 6}" type="textarea" :rows="2" ></el-input>
                </el-form-item>
          </el-card>
      </el-form>
      <div style="margin-top:20px;text-align: center;width:1000px">
          <el-button size="small" @click="toBalck">返回</el-button>
          <el-button type="primary" @click="handleConfirm" :loading="btnLoading" size="small">确定</el-button>
      </div>
  </div>
</template>
<script>
import {
  getCustomerDetailAPI,
} from '@/api/fms.js';
import {
  getCustomerInfoAPI,
  addCustomerAPI,//新增编辑客户
} from '@/api/company';
import {
  getCustomerSetting,
  getOrderUsersList,
  getAddressList,
  checkBusinessCode,
  checkContactMobile,
  getCompanyInfo,
  customerPotential,
  setCustomerIntroducer,
  addIntroducer,
  getConfigList
} from '@/api/partner'
import { formatDate } from '@/utils/date';
import { validatePhone } from '@/utils/validate';
import store from '@/store';
import { mapGetters } from 'vuex';
const defaultCustomerForm = {
  customerId:0,
  customerName:'',//    客户名称
  businessCode:'',//       社会统一信用码
  customerQuality:'',//     客户性质
  businessInfo:'',//     经营范围
  issueDate:'',//       成立日期
  regAddress:'',//     企业地址
  areaInfo:'',//      省市区文字
  provinceId:'',//     所属省ID
  cityId:'',//      所属市ID
  areaId:'',//      所属区ID
  legalPerson  :'',//    法人
  newScale:'',//      规模
  newNature:'',//      规模性质
  // newLevel:'',//       客户级别
  newIndustry:'',//      客户行业
  mainProduct:'',//      主营产品
  settlement:[],//     结算方式
  returned:'',//      回款方式
  returnedDay:'',//      账期天数
  interestRate:'',//     利率
  accountingPeriod:'',//    账期
  subsidyInterest:'',//      贴息点
  aboutBuyNum:'',//月使用量
  aboutPerProfit:'',//吨毛利
  isInvoiceNeedDetail: 1,// 开票是否明细
  subChargeIds:[],//客户协助人
  customerContact:[],//联系人
  useGoods:[],//产品信息
  customerDownstream:[],//下游客户
  customerNewType:'',//客户分类
};
const defaultDownstream = {//新增生产经营
  downstreamId:'',//id(编辑用)
  downstreamName:'',//客户名字
  product:'',//客户产品
  level: '',//客户级别
  orderRemark:'',//订单情况
};
export default {
  name: "index",
  data() {
    const isvalidatePhone = (rule, value, callback) => {
      if (!validatePhone(value)) {
        callback(new Error('请输入正确的手机号'))
      } else {
        callback()
      }
    };
    const isvalidatecustomerNewType = (rule, value, callback) => {
      if (!value && this.customerForm.newNature != 'Z(撮合)' && this.customerForm.customerQuality != '108') {
        callback(new Error('请选择客户分类'))
      } else {
        callback()
      }
    };
    return {
      customerForm: JSON.parse(JSON.stringify(defaultCustomerForm)),
      customerInfo:{},
      customerQualityList: [],
      newScaleList:[],//客户规模
      newNatureList:[],//规模性质
      newLevelList:[],//客户信息客户级别
      purchaseLevelList:[],//采购量级
      newIndustryList:[],//所属行业
      returnedList:[],//回款情况
      contactDutyList:[],//职务
      supplierNameList:[],//采购渠道
      levelList:[],//生产经营客户级别
      customerStateList: [],
      userOptionList: [],
      roles: store.getters.roles ? store.getters.roles : [],

      btnLoading: false,
      options: [],
      diQuIds: [],
      customerTypeList:[]
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
    rules:function () {
      return {
        businessCode: [{ required: this.customerForm.newNature != 'Z2(撮合)', message: '请输入社会统一信用码', trigger: 'blur'}],
        customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
        customerQuality: [{ required: true, message: '请选择客户性质', trigger: 'change' }],
        newScale:[{required: this.customerForm.newNature != 'Z2(撮合)', message: '请选择客户规模', trigger: 'change'}],
        newNature:[{ required: this.customerForm.newNature != 'Z2(撮合)', message: '请选择规模性质', trigger: 'change'}],
        customerNewType:[{
          required: this.customerForm.newNature != 'Z(撮合)'  && this.customerForm.newNature != 'Z2(撮合)' && this.customerForm.customerQuality != '108',
          trigger: 'change',
          message: '请选择客户分类',
          }],
        aboutBuyNum:[{ required: this.customerForm.newNature != 'Z2(撮合)', message: '请输入月用量', trigger: 'blur' }],
        aboutPerProfit:[{ required: this.customerForm.newNature != 'Z2(撮合)', message: '请输入预估吨毛利', trigger: 'blur' }],
        contactName: [{ required: true, message: '请输入主联系人', trigger: 'blur' }],
        contactMobile: [{
          required: true,
          validator:(rule, value, callback) => {
        if (!validatePhone(value)) {
          callback(new Error('请输入正确的手机号'))
        } else {
          callback()
        }
      },
          trigger: 'blur'}],
        contactDuty:[{ required: true, message: '请选择主联系人职位', trigger: 'change'}],
        isBuyPermission:[{ required: true, message: '请选择是否有采购决定权', trigger: 'change'}],
        legalPerson: [{ required: this.customerForm.newNature != 'Z2(撮合)', message: '请输入公司法人', trigger: 'blur' }],
        issueDate: [{ required: this.customerForm.newNature != 'Z2(撮合)', message: '请选择成立日期', trigger: 'change' }],
        returnedDay: [
          { required: true, message: '请输入账期天数', trigger: 'blur' },
        ],
        interestRate: [
          { required: true, message: '请输入利率', trigger: 'blur' },
        ],
        accountingPeriod: [
          { required: true, message: '请输入到期时间', trigger: 'blur' },
        ],
        subsidyInterest: [
          { required: true, message: '请输入贴息点数', trigger: 'blur' },
        ],
      }

    },
  },
  created() {
    this.getCustomerDetail();
    this.getCustomerInfo();
    this.getCustomerSettingList();
    this.getAddressListData();
    this.getCustomerType()
  },
  filters: {
  },
  methods: {
    changenewNature(){
      if(this.customerForm.newNature == 'Z2(撮合)'){
        this.customerForm.customerNewType = ''
        this.customerForm.customerQuality = ''
        this.customerInfo.customerQuantity = ''
        this.customerInfo.customerNewType = ''
      }
    },
    //获取客户分类列表
    getCustomerType(){
      getConfigList({status:1}).then((res)=>{
        let customerType = res.find((el)=>{
          return  el.cdtCode == 'customer_new_type'
        })
        this.customerTypeList = customerType ? customerType.data : []
      })
    },
    changeNewIndustry(){
      if(this.customerForm.newIndustry == '贸易'){
        this.customerForm.mainProduct = '贸易'
      }else{
        this.customerForm.mainProduct = ''
      }
    },
    changeQuality(){
      this.customerForm.newIndustry = '';
      this.customerForm.mainProduct = ''
    },
    // 选择地区
    chooseAreaId(value) {
      this.customerForm.areaInfo = value.length ? this.$refs["diQuIds"].getCheckedNodes()[0].pathLabels.join("") : "";
      this.customerForm.provinceId = this.diQuIds[0] ? this.diQuIds[0] : null;
      this.customerForm.cityId = this.diQuIds[1] ? this.diQuIds[1] : null;
      this.customerForm.areaId = this.diQuIds[2] ? this.diQuIds[2] : null;
    },
    // 获取客户信息配置
    getCustomerInfo() {
      getCustomerInfoAPI({tab:1}).then((res) => {
        this.newScaleList=res;
      })
      getCustomerInfoAPI({tab:2}).then((res) => {
        this.newNatureList=res;
      })
      getCustomerInfoAPI({tab:3}).then((res) => {
        this.newLevelList=res;
      })
      getCustomerInfoAPI({tab:4}).then((res) => {
        this.purchaseLevelList=res;
      })
      getCustomerInfoAPI({tab:5}).then((res) => {
        this.newIndustryList=res;
      })
      getCustomerInfoAPI({tab:6}).then((res) => {
        this.returnedList=res;
      })
      getCustomerInfoAPI({tab:7}).then((res) => {
        this.contactDutyList=res;
      })
      getCustomerInfoAPI({tab:8}).then((res) => {
        this.supplierNameList=res;
      })
      getCustomerInfoAPI({tab:9}).then((res) => {
        this.levelList=res;
      })
      // orderGoodsList().then((res) => {//厂家牌号
      // this.goodsList = res.list
      // })
    },
    // 获取客户详情
     getCustomerDetail() {
      this.loading = true;
      getCustomerDetailAPI({
        customerId:this.$route.query.customerId
      }).then((res) => {
        this.customerInfo = res;
        console.log(this.customerInfo.customerNewType,"customerInfo.customerNewType")
        this.loading = false;
        for(let key in defaultCustomerForm){
          this.customerForm[key]=res[key] || res[key] === 0 ? res[key]:defaultCustomerForm[key];
        }
        this.customerForm.customerQuality = res.customerQuantityId==0?defaultCustomerForm['customerQuantityId']:res.customerQuantityId;
        this.diQuIds = [this.customerForm.provinceId, this.customerForm.cityId, this.customerForm.areaId];
        this.customerForm.subChargeIds =res.subChargeIds!=''?res.subChargeIds.split(',').map(Number):defaultCustomerForm['subChargeIds'];
        this.getUserOptionListData();
        let data={};
        data.contactId =res.contactId;
        data.contactMobile =res.contactMobile;
        data.contactName =res.contactName;
        data.isMainContact=1;
        data.isBuyPermission=res.isBuyPermission;
        data.contactDuty=res.contactDuty;
        this.customerForm.customerContact = [];
        this.customerForm.customerContact.push(data);
      })
    },
     //删除生产经营
    delDownstream(index) {
      this.customerForm.customerDownstream.splice(index, 1)
    },
    //新增生产经营
    addDownstream() {
      this.customerForm.customerDownstream.push(JSON.parse(JSON.stringify(defaultDownstream)))
    },
    //提交新建编辑
    handleConfirm() {
      this.$refs.customerForm.validate((valid) => {
        if (valid) {
          this.btnLoading = true;
          let data=JSON.parse(JSON.stringify(this.customerForm))
          data.subChargeIds=this.customerForm.subChargeIds.join(',')
          addCustomerAPI(data).then(() => {
            this.btnLoading = false;
            this.toBalck()
          }).catch(() => {
            this.btnLoading = false;
          })
        } else {
          this.$message.error('请检查必填项');
        }
      })
    },
    //返回
    toBalck() {
      this.$router.go(-1)
    },
    //查询客户是否存在
    seachRepeat() {
      if (this.customerForm.businessCode) {
        checkBusinessCode({ businessCode: this.customerForm.businessCode, customerId: this.customerForm.customerId ? this.customerForm.customerId : 0 }).then((res) => {
          getCompanyInfo({ businessCode: this.customerForm.businessCode }).then((companyInfo) => {
            this.customerForm.businessCode = companyInfo.businessCode;
            this.customerForm.customerName = companyInfo.companyName;
            this.customerForm.businessInfo = companyInfo.businessInfo;
            this.customerForm.industry = companyInfo.industry;
            this.customerForm.issueDate = companyInfo.issueDate;
            this.customerForm.legalPerson = companyInfo.legalPerson;
            this.customerForm.phone = companyInfo.phone;
            this.customerForm.provinceId = companyInfo.provinceId;
            this.customerForm.cityId = companyInfo.cityId;
            this.customerForm.areaId = companyInfo.areaId;
            this.customerForm.addressDetail = companyInfo.regAddress;
            this.diQuIds = [this.customerForm.provinceId, this.customerForm.cityId, this.customerForm.areaId];
          })
        }).catch((rej) => {
          if (rej.code == 10001) {
            this.$alert(rej.msg, '提示', {
              confirmButtonText: '确定',
            });
            this.customerForm.businessCode = null;
          }
        })
      }
    },
    //查询手机号是否存在
    seachRepeat2() {
      if (this.customerForm.customerContact[0].contactMobile != '' && this.customerForm.customerId != '') {
        checkContactMobile({
          contactMobile: this.customerForm.customerContact[0].contactMobile,
          customerId: this.customerForm.customerId ? this.customerForm.customerId : 0,
          newNature:this.customerForm.newNature,
          contactId: this.customerForm.customerContact[0].contactId,
        }).then((res) => {
        }).catch((rej) => {
          if (rej.code == 10000 || rej.code == 10001) {
            this.$message.error(rej.msg);
            this.customerForm.customerContact[0].contactMobile = '';
          }
        })
      }
    },
    //获取员工下拉选项
    getUserOptionListData(){
      getOrderUsersList({
        status:1
      }).then((res)=>{
        this.userOptionList = res;
      })
    },

    //提交新建编辑
    // handleConfirm() {
    //   this.$refs.customerForm.validate((valid) => {
    //     if (valid) {
    //       this.btnLoading = true;
    //       this.customerForm.provinceId = this.diQuIds[0] ? this.diQuIds[0] : null;
    //       this.customerForm.cityId = this.diQuIds[1] ? this.diQuIds[1] : null;
    //       this.customerForm.areaId = this.diQuIds[2] ? this.diQuIds[2] : null;
    //       this.customerForm.transactionEndTime = parseInt(this.customerForm.transactionEndTime / 1000);
    //       updateCustomers(this.customerForm).then(() => {
    //         this.btnLoading = false;
    //         this.toBalck()
    //       }).catch(() => {
    //         this.btnLoading = false;
    //       })
    //     }
    //   })
    // },
    //获取员工下拉选项
    // getUserOptionList() {
    //   getUserOption({ status: 1 }).then((res) => {
    //     this.userOptionList = res;
    //   })
    // },

    //选择员工名称
    // handleSelectUserName(item) {
    //   this.teiJianForm2.introducerName = item.realName;
    //   this.teiJianForm2.introducerMobile = item.mobile
    //   // this.teiJianForm2.introducerName = item.realName;
    // },
    //客户名称输入匹配
    // querySearch(queryString, cb) {
    //   getCustomerOption({ keywords: queryString }).then((res) => {
    //     cb(res);
    //   })
    // },
    //选择客户名称
    // handleSelectCustomerName(item) {
    //   this.listQuery.keyword = item.customerName
    // },

    //获取客户配置
    getCustomerSettingList() {
      getCustomerSetting().then((res) => {
        res.forEach((el) => {
          if (el.cdtCode == 'customer_state') {
            this.customerStateList = el.data
          }
          else if (el.cdtCode == 'customer_quality') {//客户性质
            this.customerQualityList = el.data;
          }
          // else if (el.cdtCode == 'goods_line') {//产品线
          //   this.goodsLineList = el.data
          // }
          // else if (el.cdtCode == 'customer_degree') {
          //   this.customerDegreeList = el.data;
          // } else if (el.cdtCode == 'customer_industry') {
          //   this.customerIndustryList = el.data;
          // } else if (el.cdtCode == 'transaction_time') {
          //   this.closingTimeList = el.data
          // }
          // else if (el.cdtCode == 'goods_line') {
          //   this.goodsLineList = el.data
          // }
          // else if (el.cdtCode == 'customer_type') {
          //   this.customerTypeList = el.data;
          // } else if (el.cdtCode == 'customer_tracking') {
          //   this.customerTrackingList = el.data;
          // } else if (el.cdtCode == 'customer_source') {
          //   this.customerSourceList = el.data;
          // }
          // else if(el.cdtCode == 'viscosity_grade'){
          //   this.viscosityGradeList = el.data
          // }
        });
      })
    },
    //获取省市区列表
    getAddressListData() {
      getAddressList().then((res) => {
        this.options = res;
      })
    },

  },
};
</script>
<style scoped lang="scss">
.flexTableStyle{
  display: flex;
}
</style>

